<?php 

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
define("DEBUG",true);
class module2 extends CI_Controller {

	public function index()
	{
		exit();
	}
	
	public function tour()
	{
	
		header('Access-Control-Allow-Origin: *');
		header ("Content-Type:text/javascript");
		$client=(isset($_GET['agent'])?(int)$_GET['agent']:0);
		$agent=(isset($_GET['oto'])?(int)$_GET['oto']:0); 
		$callback = (isset($_GET["callback"])?$_GET["callback"]:'');
		$type=3;
		if($client==0||$agent==0||$callback=='')exit();
		
		
		if(!file_exists("cache/t".$client."_".$agent.".json") or DEBUG)
			{
				$this->load->model('json');
				$cont = $this->json->getlist($agent,$client,$type);
				$fh = fopen("cache/t".$client."_".$agent.".json", "w");
				fwrite($fh,$cont);
				fclose($fh);
				echo $callback.'('.$cont.');';
			}
			else
			{
				$filename = "cache/t".$client."_".$agent.".json";
				$handle = fopen($filename, "r");
				$contents = fread($handle, filesize($filename));
				echo $callback.'('.$contents.')';
				
			}
		//header ("HTTP/1.1 200");
		//
	}
	public function tour_full()
	{
		//$id=(int)$_GET['id'];
		$id=(isset($_GET['id'])?(int)$_GET['id']:0);
		if($id==0)exit();
		$callback = $_GET["callback"];
		$type=3;
		header('Access-Control-Allow-Origin: *');
		header ("Content-Type:text/json");
		if(!file_exists("cache/tf".$id.".json") or DEBUG)
		{
			$this->load->model('json');
			$cont = $this->json->getfull($type,$id);
			$fh = fopen("cache/tf".$id.".json", "w");
			fwrite($fh,$cont);
			fclose($fh);
			echo $callback.'('.$cont.')';
		}
		else
		{
			//read the file
			$filename = "cache/tf".$id.".json";
			$handle = fopen($filename, "r");
			$contents = fread($handle, filesize($filename));
			echo $callback.'('.$contents.')';
		}
	}
	public function hotel()
	{
		
		$client=(isset($_GET['agent'])?(int)$_GET['agent']:0);
		$agent=(isset($_GET['oto'])?(int)$_GET['oto']:0); 
		$callback = (isset($_GET["callback"])?$_GET["callback"]:'');
		
		if($client==0||$agent==0||$callback=='')exit();
		
		$type=1;
		//header('Access-Control-Allow-Origin: *');
		//header ("Content-Type:text/javascript");
		//header ("HTTP/1.1 200 OK");
		 $this->output->set_header("HTTP/1.1 200 OK");
		   //for IE
		   $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
		   $this->output->set_header("Cache-Control: post-check=0, pre-check=0");
		if(!file_exists("cache/h".$client."_".$agent.".json") or DEBUG)
		{
			$this->load->model('json');
			$cont = $this->json->gethotellist($client,$agent,$type);
			$fh = fopen("cache/h".$client."_".$agent.".json", "w");
			fwrite($fh,$cont);
			fclose($fh);
			echo $callback.'('.$cont.')';
		}
		else
		{
			//read the file
			$filename = "cache/h".$client."_".$agent.".json";
			$handle = fopen($filename, "r");
			$contents = fread($handle, filesize($filename));
			echo $callback.'('.$contents.');';
		}
	}
	public function excurs($client="",$agent="")
	{
		//$this->log('WTF IE!');
		$client=17;
		$agent=17;
		$type=2;
		header('Access-Control-Allow-Origin: *');
		header ("Content-Type:text/json");
		$this->load->model('json');
		if(!file_exists("cache/h".$client."_".$agent.".json") or DEBUG)
		{
			$this->load->model('json');
			$cont = $this->json->getlist($client,$agent,$type);
			$fh = fopen("cache/e".$client."_".$agent.".json", "w");
			fwrite($fh,$cont);
			fclose($fh);
			echo $cont;
		}
		else
		{
			//read the file
			$filename = "cache/e".$client."_".$agent.".json";
			$handle = fopen($filename, "r");
			$contents = fread($handle, filesize($filename));
			echo $callback.'('.$contents;
		}
	}
	public function hotel_full()
	{
		$id=(isset($_GET['id'])?(int)$_GET['id']:0);
		
		$callback = (isset($_GET["callback"])?$_GET["callback"]:'');
		
		
		
		$id=(int)$_GET['id'];
		$callback = $_GET["callback"];
		if($id==0)exit();
		$type=1;
		header('Access-Control-Allow-Origin: *');
		header ("Content-Type:text/json");
		if(!file_exists("cache/hf".$id.".json") or DEBUG)
		{
			$this->load->model('json');
			$cont = $this->json->gethotelfull($id);
			$fh = fopen("cache/hf".$id.".json", "w");
			fwrite($fh,$cont);
			fclose($fh);
			echo $callback.'('.$cont.')';
		}
		else
		{
			//read the file
			$filename = "cache/hf".$id.".json";
			$handle = fopen($filename, "r");
			$contents = fread($handle, filesize($filename));
			echo $callback.'('.$contents.')';
		}
		
		
	}
	public function excurs_full($id=0)
	{
		$id=(isset($_GET['id'])?(int)$_GET['id']:0);
		
		$callback = (isset($_GET["callback"])?$_GET["callback"]:'');
		
		
		
		if($id==0)exit();
		$type=2;
		header('Access-Control-Allow-Origin: *');
		header ("Content-Type:text/json");
		if(!file_exists("cache/ef".$id.".json") or DEBUG)
		{
			$this->load->model('json');
			$cont = $this->json->getfull($type,$id);
			$fh = fopen("cache/ef".$id.".json", "w");
			fwrite($fh,$cont);
			fclose($fh);
			echo $callback.'('.$cont.')';
		}
		else
		{
			//read the file
			$filename = "cache/ef".$id.".json";
			$handle = fopen($filename, "r");
			$contents = fread($handle, filesize($filename));
			echo $callback.'('.$contents.')';
		}
	
	
	}
	public function showplace_full($id=0)
	{
		$id=(isset($_GET['id'])?(int)$_GET['id']:0);
		
		$callback = (isset($_GET["callback"])?$_GET["callback"]:'');
		
		if($id==0)exit();
		$type=4;
		header('Access-Control-Allow-Origin: *');
		header ("Content-Type:text/json");
		if(!file_exists("cache/sf".$id.".json") or DEBUG)
		{
			$this->load->model('json');
			$cont = $this->json->getfull($type,$id);
			$fh = fopen("cache/sf".$id.".json", "w");
			fwrite($fh,$cont);
			fclose($fh);
			echo $callback.'('.$cont.')';
		}
		else
		{
			//read the file
			$filename = "cache/sf".$id.".json";
			$handle = fopen($filename, "r");
			$contents = fread($handle, filesize($filename));
			echo $callback.'('.$contents.')';
		}
	
	
	}
	public function hotel_foto()
	{
		$id=(isset($_GET['id'])?(int)$_GET['id']:0);
		
		$callback = (isset($_GET["callback"])?$_GET["callback"]:'');
		
		if($id==0)
		{
			exit();
		}
		
		header('Access-Control-Allow-Origin: *');
		header ("Content-Type:text/json");
		if(!file_exists("cache/f".$id.".json") or DEBUG)
		{
			$this->load->model('json');
			$cont = $this->json->get_foto($id);
			$fh = fopen("cache/f".$id.".json", "w");
			fwrite($fh,$cont);
			fclose($fh);
			echo $callback.'('.$cont.')';
		}
		else
		{
			//read the file
			$filename = "cache/f".$id.".json";
			$handle = fopen($filename, "r");
			$contents = fread($handle, filesize($filename));
			echo $callback.'('.$contents.')';
		}
	}
	public function tour_foto()
	{
		$id=(isset($_GET['id'])?(int)$_GET['id']:0);
		
		$callback = (isset($_GET["callback"])?$_GET["callback"]:'');
		
		if($id==0)
		{
			exit();
		}
	
		header('Access-Control-Allow-Origin: *');
		header ("Content-Type:text/json");
		if(!file_exists("cache/f".$id.".json") or DEBUG)
		{
			$this->load->model('json');
			$cont = $this->json->get_foto($id);
			$fh = fopen("cache/f".$id.".json", "w");
			fwrite($fh,$cont);
			fclose($fh);
			echo $callback.'('.$cont.')';
		}
		else
		{
			//read the file
			$filename = "cache/f".$id.".json";
			$handle = fopen($filename, "r");
			$contents = fread($handle, filesize($filename));
			echo $callback.'('.$contents.')';
		}
	}
	public function foto()
	{
		$id=(isset($_GET['id'])?(int)$_GET['id']:0);
		
		$callback = (isset($_GET["callback"])?$_GET["callback"]:'');
		
		if($id==0)
		{
			exit();
		}
	
		header('Access-Control-Allow-Origin: *');
		header ("Content-Type:text/json");
		if(!file_exists("cache/f".$id.".json") or DEBUG)
		{
			$this->load->model('json');
			$cont = $this->json->get_foto($id);
			$fh = fopen("cache/f".$id.".json", "w");
			fwrite($fh,$cont);
			fclose($fh);
			echo $callback.'('.$cont.')';
		}
		else
		{
			//read the file
			$filename = "cache/f".$id.".json";
			$handle = fopen($filename, "r");
			$contents = fread($handle, filesize($filename));
			echo $callback.'('.$contents.')';
		}
	}
	public function city($id=0)
	{
		$id=(isset($_GET['id'])?(int)$_GET['id']:0);
		
		$callback = (isset($_GET["callback"])?$_GET["callback"]:'');
		
		if($id==0)
		{
			exit();
		}
		$type=5;
		header('Access-Control-Allow-Origin: *');
		header ("Content-Type:text/json");
		if(!file_exists("cache/ci".$id.".json") or DEBUG)
		{
			$this->load->model('json');
			$cont = $this->json->getfull($type,$id);
			$fh = fopen("cache/ci".$id.".json", "w");
			fwrite($fh,$cont);
			fclose($fh);
			echo $callback.'('.$cont.')';
		}
		else
		{
			//read the file
			$filename = "cache/ci".$id.".json";
			$handle = fopen($filename, "r");
			$contents = fread($handle, filesize($filename));
			echo $callback.'('.$contents.')';
		}
	}
	
}